* Figure 1

*Load data
import delimited "../processed data/f1_results.csv", clear
*Rename variables sequentially
local i = 1
foreach var of varlist * {
    rename `var' var`i'
    local i = `i' + 1
}
rename var19 alpha
rename var20 alpha_rho
rename var21 alpha_l

* simulated elasticity
rename var1 el_w_simu
rename var5 el_rho_simu

* analytical elasticity
rename var2 el_w_analytical
rename var6 el_rho_analytical

* Model errors
g upper = -0.169 + 0.04
g lower = -0.169 - 0.04
g upper2 = -0.146 + 0.04
g lower2 = -0.146 - 0.04


* chose solution method
local method simu
g undershoot_w = el_w_`method'>=upper
g undershoot_r = el_rho_`method'>=upper2 

g overshoot_w = el_w_`method'<=lower 
g overshoot_r = el_rho_`method'<=lower2 

g w_error = overshoot_w -undershoot_w 
g r_error = overshoot_r -undershoot_r 
egen groups = group(w_error r_error)


**************
* area plots
bys group alpha_l alpha: egen max_alpha_roh = max(alpha_rho)

* ALPHA = 0.4
preserve
keep if alpha>0.39 & alpha<0.41
drop if alpha_rho>=1.2

replace alpha_l=0.75 if alpha_l<1 & r_error==-1 & w_error==-1 
*to make the orange region cover the top grey part

*Comparing blue and olive area plots at the cliff
*-blue area plot
tab alpha_l max_alpha_roh if r_error==1 & w_error==0  & alpha_l>0.67 & alpha_l <0.69

*-olive area plot
tab alpha_l max_alpha_roh if  r_error==1 & w_error==-1 & alpha_l>0.67 & alpha_l <0.69
*The value of max_alpha_roh for the r_error==1 & w_error==-1 conditions need to be changed to 0.37 for the cliff to disappear
replace max_alpha_roh=0.37 if  r_error==1 & w_error==-1 & alpha_l>0.67 & alpha_l <0.69


*Comparing blue and greeb area plots at the cliff
*-blue area plot
codebook alpha_l max_alpha_roh if r_error==1 & w_error==0 & alpha_l>0.59 & alpha_l<0.62

*-green area plot
codebook alpha_l max_alpha_roh if r_error==0 & w_error==0 & alpha_l>0.59
*the value of max_alpha_roh for the r_error==0 & w_error==0 conditions need to be changed to 0.4 for the ciff to disappear
replace max_alpha_roh=0.4 if r_error==0 & w_error==0 & alpha_l>0.59


tw (line max_alpha_roh alpha_l if r_error==-1 & w_error==-1 ,color(orange) recast(area) ) (lowess max_alpha_roh alpha_l if  r_error==0 & w_error==-1, color(red) recast(area)) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==-1, color(olive) recast(area) ) (lowess max_alpha_roh alpha_l if r_error==0 & w_error==0, color(green) recast(area) ) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==0, color(blue) recast(area)) (lowess max_alpha_roh alpha_l if  r_error==1 & w_error==1, color(black) recast(area)),  xtitle("{&alpha}{sub:l}") ytitle("{&alpha}{sub:{&rho}}")  ylabel(0 (0.2) 1.2) legend(order(1 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&darr}" 2 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}✓" 3 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&uarr}" 4 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}✓" 5 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}{&uarr}" 6 "{&epsilon}{sub:w}{&uarr}, {&epsilon}{sub:{&rho}}{&uarr}" ) rowgap(0)  symysize(10) symxsize(5) )
*had to use 'line' for the orange section because lowess shaded wasn't generating a smooth graph

graph export ../output/Figure1a.pdf, replace 

restore

* ALPHA = 0.7
preserve
keep if alpha>0.69 & alpha<0.71
drop if alpha_rho>=1.2
tw (lowess max_alpha_roh alpha_l if r_error==-1 & w_error==-1 ,color(orange) recast(area) ) (lowess max_alpha_roh alpha_l if  r_error==0 & w_error==-1, color(red) recast(area) ) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==-1, color(olive) recast(area) ) (lowess max_alpha_roh alpha_l if r_error==0 & w_error==0, color(green) recast(area)  ) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==0, color(blue) recast(area)) (lowess max_alpha_roh alpha_l if  r_error==1 & w_error==1, color(black) recast(area)),  xtitle("{&alpha}{sub:l}") ytitle("{&alpha}{sub:{&rho}}") yscale(range(0 1.2)) ylabel(0 (0.2) 1.2) legend(order(1 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&darr}" 2 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}✓" 3 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&uarr}" 4 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}✓" 5 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}{&uarr}" 6 "{&epsilon}{sub:w}{&uarr}, {&epsilon}{sub:{&rho}}{&uarr}" ) rowgap(0)  symysize(10) symxsize(5) )

graph export ../output/Figure1b.pdf, replace 

restore

* ALPHA = 1
preserve
keep if alpha==1
drop if alpha_rho>=1.2
tw (lowess max_alpha_roh alpha_l if r_error==-1 & w_error==-1 ,color(orange) recast(area) ) (lowess max_alpha_roh alpha_l if  r_error==0 & w_error==-1, color(red) recast(area)) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==-1, color(olive) recast(area) ) (lowess max_alpha_roh alpha_l if r_error==0 & w_error==0, color(green) recast(area)) (lowess max_alpha_roh alpha_l if r_error==1 & w_error==0, color(blue) recast(area) ) (lowess max_alpha_roh alpha_l if  r_error==1 & w_error==1, color(black) recast(area)),  xtitle("{&alpha}{sub:l}") ytitle("{&alpha}{sub:{&rho}}") yscale(range(0 1.2)) ylabel(0 (0.2) 1.2) legend(order(1 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&darr}" 2 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}✓" 3 "{&epsilon}{sub:w}{&darr}, {&epsilon}{sub:{&rho}}{&uarr}" 4 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}✓" 5 "{&epsilon}{sub:w}✓, {&epsilon}{sub:{&rho}}{&uarr}" 6 "{&epsilon}{sub:w}{&uarr}, {&epsilon}{sub:{&rho}}{&uarr}") rowgap(0)  symysize(10) symxsize(5) )

graph export ../output/Figure1c.pdf, replace 

restore
